export default {
   namespaced:true,
   state:() => ({
     address:JSON.parse(uni.getStorageSync('uni-address')||'{}'),
     token:uni.getStorageSync('uni-token')||'',
     userInfo:JSON.parse(uni.getStorageSync('uni-userInfo')||'{}'),
     redirectInfo:uni.getStorageSync('uni-redirectInfo')||''
   }),
   mutations:{
     updateAddress(state,address){
       state.address = address
       this.commit('m_user/saveAddressToStorage')
     },
     saveAddressToStorage(state){
       uni.setStorageSync('uni-address',JSON.stringify(state.address))
     },
     updateUserInfo(state,userinfo){
       state.userInfo = userinfo
       this.commit('m_user/saveUserInfo')
     },
     saveUserInfo(state){
       uni.setStorageSync('uni-userInfo',JSON.stringify(state.userInfo))
     },
     updateToken(state,token){
       state.token=token
       this.commit('m_user/saveToken')
     },
     saveToken(state){
       uni.setStorageSync('uni-token',JSON.stringify(state.token))
     },
     updateRedirectInfo(state,redirectInfo){
       state.redirectInfo=redirectInfo
       this.commit('m_user/saveRedirectInfo')
     },
     saveRedirectInfo(state){
       uni.setStorageSync('uni-redirectInfo',JSON.stringify(state.redirectInfo))
     }
   },
   getters:{
     addstr(state) {
       if (!state.address.provinceName) return ''
       // 拼接 省，市，区，详细地址 的字符串并返回给用户
       return state.address.provinceName + state.address.cityName + state.address.countyName + state.address.detailInfo
     }
   }
}